// @Author EthanScriptOn
// @Desc
package identity

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_basic_components/tool"
)

// PrefixedObjectId Generate a prefixed identity
type PrefixedObjectId struct {
	generatorStrategy IdentityInformation
	prefix            string
}

func (p *PrefixedObjectId) GenerateUniqueIdentifier() (identifier interface{}, err error) {
	defer tool.HandleErr(&err)
	identifier, err = p.generatorStrategy.GenerateUniqueIdentifier()
	if err != nil {
		return nil, err
	}
	return fmt.Sprintf("[%v]-[%v]", p.prefix, identifier), nil
}

func GeneratePrefixedObjectId(strategy IdentityInformation, prefix string) *PrefixedObjectId {
	return &PrefixedObjectId{
		generatorStrategy: strategy,
		prefix:            prefix,
	}
}
